package lif.config;

import java.util.List;
import java.util.Map;
import java.util.Properties;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.validation.MessageCodesResolver;
import org.springframework.validation.Validator;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.AsyncSupportConfigurer;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter;
import org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter;
import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.XmlViewResolver;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import freemarker.template.utility.XmlEscape;
import lif.controller.MyContrllerForBeanName;

@Configuration
//@EnableWebMvc
@ComponentScan(basePackages = "lif.controller")
public class WebConfig
{
    
    @Bean
    public FreeMarkerConfigurer freeMarkerConfigurer()
    {
        /*
         *  <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="templateLoaderPath"><value>/WEB-INF/freemarker/</value></property>
        </bean>
        
         */
        FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
        freeMarkerConfigurer.setTemplateLoaderPath("/fm/");
        Properties settings = new Properties();
        settings.setProperty("number_format", "0.######");
        freeMarkerConfigurer.setFreemarkerSettings(settings);
        Map variables = new java.util.HashMap<String, Object>();
        variables.put("xml_escape", new XmlEscape());
        freeMarkerConfigurer.setFreemarkerVariables(variables);
        return freeMarkerConfigurer;
    }
    
    @Bean
    public HttpRequestHandlerAdapter httpRequestHandlerAdapter()
    {
        HttpRequestHandlerAdapter ha = new HttpRequestHandlerAdapter();
        return ha;
        
    }
    
    @Bean
    public SimpleControllerHandlerAdapter simpleControllerHandlerAdapter()
    {
        SimpleControllerHandlerAdapter sca = new SimpleControllerHandlerAdapter();
        return sca;
        
    }
    
    @Bean
    public BeanNameUrlHandlerMapping beanNameUrlHandlerMapping()
    {
        BeanNameUrlHandlerMapping bnul = new BeanNameUrlHandlerMapping();
        return bnul;
        
    }
    
    @Bean
    public RequestMappingHandlerMapping requestMappingHandlerMapping()
    {
        RequestMappingHandlerMapping bnul = new RequestMappingHandlerMapping();
        return bnul;
        
    }
    
    @Bean(name = "/bc")
    public MyContrllerForBeanName myContrllerForBeanName()
    {
        MyContrllerForBeanName mycontroller = new MyContrllerForBeanName();
        return mycontroller;
    }
    
    @Bean
    public ViewResolver internalResourceViewResolver()
    {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/");
        viewResolver.setSuffix(".jsp");
        viewResolver.setOrder(4);
        return viewResolver;
    }
    
    @Bean
    public ViewResolver viewResolver3()
    {
        XmlViewResolver viewResolver = new XmlViewResolver();
        viewResolver.setOrder(4);
        return viewResolver;
    }
    
}
